home *** CD-ROM | disk | FTP | other *** search
Wrap
#! /bin/sh # postinst script for cups # # see: dh_installdeb(1) set -e # summary of how this script can be called: # * <postinst> `configure' <most-recently-configured-version> # * <old-postinst> `abort-upgrade' <new version> # * <conflictor's-postinst> `abort-remove' `in-favour' <package> # <new-version> # * <deconfigured's-postinst> `abort-deconfigure' `in-favour' # <failed-install-package> <version> `removing' # <conflicting-package> <version> # for details, see /usr/doc/packaging-manual/ # # quoting from the policy: # Any necessary prompting should almost always be confined to the # post-installation script, and should be protected with a conditional # so that unnecessary prompting doesn't happen if a package's # installation fails and the `postinst' is called with `abort-upgrade', # `abort-remove' or `abort-deconfigure'. # Debconf . /usr/share/debconf/confmodule # Default Configuration file if [ -e /etc/default/cups ]; then . /etc/default/cups fi case "$1" in configure) # Set up lpadmin group. if [ -z "`getent group lpadmin`" ]; then addgroup --system lpadmin fi if [ -L /usr/share/ppd/cups-transitional-dir ]; then rm -f /usr/share/ppd/cups-transitional-dir fi if [ -L /usr/share/cups/model/cups-included ]; then rm -f /usr/share/cups/model/cups-included fi # Generate raw MIME handling files if they don't already exist. if [ ! -e /etc/cups/raw.types ]; then cat >/etc/cups/raw.types <<EOF # This file was generated by the cups package. You may change it, or # reconfigure this file with dpkg-reconfigure. If it is removed, it # will be regenerated by the package scripts. application/octet-stream EOF fi if [ ! -e /etc/cups/raw.convs ]; then cat >/etc/cups/raw.convs <<EOF # This file was generated by the cups package. You may change it, or # reconfigure this file with dpkg-reconfigure. If it is removed, it # will be regenerated by the package scripts. application/octet-stream application/vnd.cups-raw 0 - EOF fi # Set up raw printing of application/octet-stream if desired. db_fget cupsys/raw-print changed if [ "$RET" = "true" ]; then mv /etc/cups/raw.convs /etc/cups/raw.convs-convert db_get cupsys/raw-print if [ "$RET" = "true" ]; then sed 's/^\s*#\s*application/application/' \ < /etc/cups/raw.convs-convert > /etc/cups/raw.convs else sed 's/^application/#application/' \ < /etc/cups/raw.convs-convert > /etc/cups/raw.convs fi rm -f /etc/cups/raw.convs-convert db_fset cupsys/raw-print changed false fi # Set up backends db_get cupsys/backend && SELECTED=$RET list=`echo $SELECTED | sed -e 's/, /,/g'` save_IFS=$IFS IFS=, (cd /usr/lib/cups/backend && rm -f http ipp lpd parallel scsi serial socket usb snmp dnssd) for module in $list; do ln /usr/lib/cups/backend-available/$module /usr/lib/cups/backend/$module if [ "$module" = "ipp" ]; then ln /usr/lib/cups/backend/ipp /usr/lib/cups/backend/http fi done IFS=$save_IFS # activate new backends on upgrades db_fset cupsys/backend changed false if dpkg --compare-versions "$2" lt-nl "1.3.4-2"; then for module in snmp scsi serial dnssd; do [ -e /usr/lib/cups/backend/$module ] || \ ln /usr/lib/cups/backend-available/$module /usr/lib/cups/backend/$module done fi # Resync Debconf database with real state list=`( cd /usr/lib/cups/backend && for f in ipp lpd parallel scsi serial socket usb snmp dnssd; do [ -e $f ] && echo -n "$f, "; done ) | sed -e 's/, $//'` db_set cupsys/backend $list; if [ -f /etc/cups/classes.conf ]; then chown root:lp /etc/cups/classes.conf ; chmod 600 /etc/cups/classes.conf fi if [ -f /etc/cups/printers.conf ]; then chown root:lp /etc/cups/printers.conf ; chmod 600 /etc/cups/printers.conf fi # Add symlink to local files required by LSB if [ ! -e /usr/share/ppd/1-local-admin -a ! -L /usr/share/ppd/1-local-admin ]; then ln -s /usr/local/share/ppd /usr/share/ppd/1-local-admin fi if [ ! -e /usr/share/ppd/2-third-party -a ! -L /usr/share/ppd/2-third-party ]; then ln -s /opt/share/ppd /usr/share/ppd/2-third-party fi # symlink snakeoil SSL certificate if present if [ -e /etc/ssl/certs/ssl-cert-snakeoil.pem -a \ -e /etc/ssl/private/ssl-cert-snakeoil.key -a \ -n "`getent group ssl-cert`" -a ! -e /etc/cups/ssl/server.crt -a \ ! -e /etc/cups/ssl/server.key ]; then ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/cups/ssl/server.crt ln -s /etc/ssl/private/ssl-cert-snakeoil.key /etc/cups/ssl/server.key fi # Remove shutdown and reboot links; this init script does not need them. if dpkg --compare-versions "$2" lt-nl "1.3.6-2"; then rm -f /etc/rc0.d/K??cups /etc/rc6.d/K??cups fi # Reload AppArmor profile if present if [ -e /etc/apparmor.d/usr.sbin.cupsd ] && [ -x /etc/init.d/apparmor ]; then invoke-rc.d apparmor force-reload || true fi # init.d priority transition if dpkg --compare-versions "$2" le-nl "1.3.9-15"; then for l in 2 3 4 5; do old=/etc/rc${l}.d/S20cups new=/etc/rc${l}.d/S50cups if [ -e "$old" ] && [ ! -e "$new" ]; then mv "$old" "$new" fi done fi ;; abort-upgrade|abort-remove|abort-deconfigure) ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 0 ;; esac # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. # Automatically added by dh_installdocs if [ "$1" = configure ] && which install-docs >/dev/null 2>&1; then install-docs -i /usr/share/doc-base/cups fi # End automatically added section # Automatically added by dh_installinit if [ -x "/etc/init.d/cups" ]; then update-rc.d cups start 50 2 3 4 5 . stop 80 1 . >/dev/null if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then invoke-rc.d cups start || exit $? else /etc/init.d/cups start || exit $? fi fi # End automatically added section # Automatically added by dh_usrlocal if [ "$1" = configure ]; then ( while read line; do set -- $line dir="$1"; mode="$2"; user="$3"; group="$4" if [ ! -e "$dir" ]; then if mkdir "$dir" 2>/dev/null; then chown "$user":"$group" "$dir" chmod "$mode" "$dir" fi fi done ) << DATA /usr/local/share 2775 root staff /usr/local/share/ppd 2775 root staff DATA fi # End automatically added section if [ "$1" = configure ]; then # Do the following only if CUPS is running and the needed CUPS tools # are available if which lpstat > /dev/null 2>&1 && \ which lpinfo > /dev/null 2>&1 && \ which lpadmin > /dev/null 2>&1 && \ lpstat -r > /dev/null 2>&1; then # Update the PPD files of all already installed print queues driverregexp='^lsb/usr/cups-included/' gennicknameregexp='s/,\s*\d+\.\d+[\d\.]*$//i' [ ! -z "$gennicknameregexp" ] && \ gennicknameregexp="; $gennicknameregexp" gennicknameregexp='s/\s*\(recommended\)//'"$gennicknameregexp" tempfiles= trap 'rm -f $tempfiles; exit 0' 0 1 2 13 15 tmpfile1=`mktemp -t updateppds.XXXXXX` tempfiles="$tempfiles $tmpfile1" lpinfo -m | grep -E $driverregexp > $tmpfile1 cd /etc/cups/ppd for ppd in *.ppd; do [ -r "$ppd" ] || continue queue=${ppd%.ppd} lpstat -p "$queue" >/dev/null 2>&1 || continue nickname=`grep '\*NickName:' "$ppd" | cut -d '"' -f 2 | perl -p -e 's/\n$//' | perl -p -e "$gennicknameregexp" | perl -p -e 's/(\W)/\\\\$1/g'` lang=`grep '\*LanguageVersion:' "$ppd" | cut -d ' ' -f 2 | perl -e 'print lc(<>)' | perl -p -e 's/[\r\n]//gs'` ppdfound="0" englishppduri="" tmpfile2=`mktemp -t updateppds.XXXXXX` tempfiles="$tempfiles $tmpfile2" cat $tmpfile1 | perl -p -e "$gennicknameregexp" | grep -E '^\S+\s+.*'"$nickname"'$' | cut -d ' ' -f 1 > $tmpfile2 while read newppduri; do [ "$ppdfound" = "0" ] && lpadmin -p "$queue" -m $newppduri 2>/dev/null || continue newlang=`grep '\*LanguageVersion:' "$ppd" | cut -d ' ' -f 2 | perl -e 'print lc(<>)' | perl -p -e 's/[\r\n]//gs'` [ "$newlang" = "$lang" ] && ppdfound="1" [ "$newlang" = "english" ] && englishppduri="$newppduri" done < $tmpfile2 [ "$ppdfound" = "0" ] && [ ! -z "$englishppduri" ] && lpadmin -p "$queue" -m $englishppduri 2>/dev/null && ppdfound="1" [ "$ppdfound" = "1" ] && echo PPD for printer $queue updated >&2 done fi fi db_stop exit 0